<?php

require_once "../db/${GLOBALS['__DBTYPE']}/get/thread.php";

define('DEFAULT_THREAD_PAGE_SIZE', 15);
define('DEFAULT_THREAD_PAGE_START', 1);

function showPage($_PGE, $_TPL, $data) {
  $psize = ((int)$data['psize'] > 0) ? intval((int)$data['psize']) : DEFAULT_THREAD_PAGE_SIZE;
  if( $data['fid'] > 0 ) {
    $fid = (int)intval($data['fid']);
    $page = ($data['page'] > 0) ? (int)intval($data['page']) : DEFAULT_THREAD_PAGE_START;
  } elseif( $data['tnum'] > 0 ) {
    // aye' lass slightly slower, but what can ya do, now?
    $tid = (int)intval($data['tnum']);

    // Yes, this doesn't work. :\ Maybe change to getFidFromTid( $tid ); ?
    //  Then just place on front page
    $thread = getThread( $tid );
    $fid = $thread['fid'];
    $start = ($thread['tid'] > $inc) ? (int)(($thread['tid']-1)/$inc)*$inc : 0;
    $thread = NULL;
  } else {
    die( "BREAKAGE1!" ); // BREAKAGE
  }

  $threads = getThreads( $fid, ($page-1)*$psize, $psize );
  $count = threadCount($fid);

  for( $i = count($threads)-1; $i > -1; --$i ){ 
    // we need to desmurf all the smurfs, but where? Not in template
   // $threads[$i]['datum'] = smurf($threads[$i]['datum'], $threads[$i]['smurfKey']);
  }  

  $_TPL['fid'] = $fid;
  $_TPL['ftitle'] = $threads[0]['ftitle'];
  $_TPL['threads'] = $threads;
  $_TPL['count'] = $count;
  $_TPL['page'] = $page;
  $_TPL['psize'] = $psize;

  $_PGE = 'Thread';

}

?>
